<div class="easyui-panel" data-options="fit:true,border:0" style="width:80%;padding: 40px 80px;">
    <div class="form-row">
        <div class="alert-warning">
            <div class="alert-icons"></div>
            <b>这是微信的主要配置文件，如无特殊需要请勿自行修改，谢谢。</b>
        </div>
    </div>
    <form id="mpSettingForm" name="mpSettingForm" action="${base}/admin/wechat/updateMPInfo.do" method="POST">
        <div class="form-row">
            <label class="label-top">微信原始ID:</label>
            <input name="mpId" id="mpId" class="easyui-textbox theme-textbox-radius" data-options="required:true">
        </div>
        <div class="form-row">
            <label class="label-top">微信昵称:</label>
            <input name="nickName" id="nickName" class="easyui-textbox theme-textbox-radius"
                   data-options="required:true">
        </div>
        <div class="form-row">
            <label class="label-top">应用ID:</label>
            <input name="appId" id="appId" class="easyui-textbox theme-textbox-radius" data-options="required:true">
        </div>
        <div class="form-row">
            <label class="label-top">应用密钥:</label>
            <input name="appSecret" id="appSecret" class="easyui-textbox theme-textbox-radius"
                   data-options="required:true">
        </div>
        <div class="form-row">
            <label class="label-top">AESKey（通讯加密）:</label>
            <input name="aesKey" id="aesKey" class="easyui-textbox theme-textbox-radius" data-options="required:true">
        </div>
        <div class="form-row">
            <label class="label-top">高级API密钥:</label>
            <input name="accessToken" id="accessToken" class="easyui-textbox theme-textbox-radius"
                   style="width:98%; height:60px;" data-options="multiline:true,disabled:true">
        </div>
        <div class="form-row">
            <label class="label-top">API密钥有效时间:</label>
            <input id="atExpireTime" class="easyui-textbox theme-textbox-radius"
                   data-options="disabled:true"/>
            <input id="atExpireTimeHid" name="atExpireTime" type="hidden"/>
        </div>
        <div class="form-row">
            <label class="label-top">JSSDK票据:</label>
            <input name="jsTicket" id="jsTicket" class="easyui-textbox theme-textbox-radius"
                   style="width:98%; height:60px;" data-options="multiline:true,disabled:true">
        </div>
        <div class="form-row">
            <label class="label-top" style="display:block;">票据有效时间:</label>
            <input id="jtExpireTime" class="easyui-textbox theme-textbox-radius"
                   data-options="disabled:true"/>
            <input id="jtExpireTimeHid" name="jtExpireTime" type="hidden"/>
        </div>
        <div class="form-row">
            <label class="label-top" style="display:block;">启用/禁用:</label>
            <input id="dataStatusBtn" class="easyui-switchbutton" data-options="onText:'开启',offText:'禁用'">
            <input id="dataStatus" name="dataStatus" type="hidden">
        </div>
        <div class="form-row">
            <label class="label-top">备注:</label>
            <input name="remarks" id="remarks" class="easyui-textbox theme-textbox-radius"
                   style="width:98%; height:80px;" data-options="multiline:true">
        </div>
    </form>
</div>

<div style="position:absolute;bottom:0px;left:0px;width:100%;z-index:9999;text-align:center;background-color:rgba(34, 36, 38, 0.15);">
    <a id="refreshBtn" href="#" class="easyui-linkbutton button-orange button-xs l-btn l-btn-small" style="font-size:12px;width: 40%">
        <span class="l-btn-left">
            <span class="l-btn-text">
                <i class="iconfont">&#xe6aa;</i> 刷新信息
            </span>
        </span>
    </a>
    <a id="submitBtn" href="#" class="easyui-linkbutton button-orange button-xs l-btn l-btn-small" style="font-size:12px;width: 40%">
        <span class="l-btn-left">
            <span class="l-btn-text">
                <i class="iconfont">&#xe6b1;</i> 更新微信配置
            </span>
        </span>
    </a>
</div>


<script>
    $(function () {

        $('#dataStatusBtn').switchbutton({
            'onChange': function (checked) {
                if (checked) {
                    $('#dataStatus').val('0')
                } else {
                    $('#dataStatus').val('2')
                }
            }
        })

        $('#mpSettingForm').form({
            'onLoadSuccess': function (data) {
                if (data.dataStatus == '0') {
                    $('#dataStatusBtn').switchbutton('check');
                } else {
                    $('#dataStatusBtn').switchbutton('uncheck');
                }

                var atTime = $('#atExpireTimeHid').val();
                var jtTime = $('#jtExpireTimeHid').val();

                if (atTime != '') {
                    $('#atExpireTime').textbox('setValue', dateFormat(atTime));
                }

                if (jtTime != '') {
                    $('#jtExpireTime').textbox('setValue', dateFormat(jtTime));
                }
            }
        });

        reloadMPFrm();

        $('#refreshBtn').bind('click', function () {
            reloadMPFrm();
        });

        $('#submitBtn').bind('click', function () {
            submitFrm('mpSettingForm', '更新微信配置信息');
        });
    });

    function reloadMPFrm() {
        reloadFrm('mpSettingForm', '${base}/admin/wechat/getMPInfo.do');
    }

    function dateFormat(dateTime){

        var date = new Date();
        date.setTime(dateTime);
        var dateStr = date.getFullYear();
        var month = date.getMonth() + 1;
        var day = date.getDate();
        var hour = date.getHours();
        var minus = date.getMinutes();
        var seconds = date.getSeconds();

        dateStr += '/'+(month >= 10 ? month : '0'+month);
        dateStr += '/'+(day >= 10 ? day : '0'+day);
        dateStr += ' '+(hour >= 10 ? hour : '0'+hour);
        dateStr += ':'+(minus >= 10 ? minus : '0'+minus);
        dateStr += ':'+(seconds >= 10 ? seconds : '0'+seconds);

        return dateStr;
    }
</script>
